@extends('Admin.base')
@section('css')
    <link rel="stylesheet" href="/Admin/layuiadmin/css/extend/formSelects-v4.css" media="all">
@endsection
@section('style')

@endsection
@section('content')

    <div class="layui-card">
        <div class="layui-card-header layuiadmin-card-header-auto">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>在售库存表</legend>
            </fieldset>
        </div>
        <div class="layui-form layui-card-header layuiadmin-card-header-auto ">
            <div class="layui-form-item layui-row">
                <div class="layui-col-md6" >
                    <label class="layui-form-label">关键词</label>
                    <div class="layui-input-block">
                        <input type="text" name="keyword" placeholder="请输入商品名称、ID、品牌" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-block">
                        <select name="status" > 
                            <option value="">售卖状态</option> 
                            @foreach (\App\Models\Goods::SALE_STATUS as $id => $name) 
                            <option value="{{$id ?? 0}}">{{$name ?? ''}}</option> 
                            @endforeach
                          </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-btn-group layui-input-block">
                        <button class="layui-btn layui-btn-sm layui-input-block layuiadmin-btn-admin" lay-submit lay-filter="LAY-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="LAY-table" lay-filter="LAY-table"></table>
        </div>
    </div>
@endsection
@section('script')
    <script src="/js/ajax.js"></script>
    <script>
        layui.use(['form', 'table', 'formSelects'], function(){
            var $ = layui.$
                    ,form = layui.form
                    ,table = layui.table

            var tableins = table.render({
                elem: '#LAY-table'
                ,title: "商品库存表"
                ,id: 'list'
                ,width: 1200
                ,url: "{{route("store.tabelList")}}"
                ,method: "post"
                ,page: true
                ,limit:10
                ,cols: [[
                    {field: 'photo', title: '缩略图',templet:function(d){return  d.photo ? '<img src="'+ d.photo + '" width="50px" height="50px" />' : ""}} 
                    ,{field: '',width:350, title: '商品信息',templet: function(d){
                        d.sku = d.sku ? d.sku : "";
                        d.good_brands = d.goods_brand ? d.goods_brand['name'] :"" ;
                        return  d.goods_name +'<br>'+  d.sku  +'<br>' + d.good_brands;
                    }} 
                    ,{field: 'price', title: '销售价格'} 
                    ,{field: 'status', title: '售卖状态',templet:function(d){
                       return d.status == 1 ? (d.stock == 0 ? "已售罄" : "上架") : "下架";
                     }} 
                    ,{field: 'stock', title: '当前库存',sort: true} 
                    ,{field: 'amount_sum', title: '历史销量',sort: true} 
                    ,{field: 'amount_sum7', title: '近七天销量',sort: true}
                ]]
            });

            //监听搜索
            form.on('submit(LAY-search)', function(data){
                var field = data.field;
                //执行重载
                table.reload('list', {
                    where: field,page: {curr: 1}
                });

            });
        });
    </script>

@endsection